package com.itheima.CSM_preX.aabService;

import com.itheima.CSM_preX.aabService.Serv.SetmealServ;
import com.itheima.CSM_preX.aacMapper.SetmealMapper;
import com.itheima.pojo.Entity.CheckGroup;
import com.itheima.pojo.Entity.CheckItem;
import com.itheima.pojo.Entity.Setmeal;
import com.itheima.pojo.VO.VOMOBsGet;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SetmealImpl implements SetmealServ {
    @Autowired
    private SetmealMapper setmealMapper;


    @Override
    public List<VOMOBsGet> getSetmeal() {
        List<Setmeal> kks = setmealMapper.getSetmeal();
        List<VOMOBsGet> vvs = new ArrayList<>();
        for (Setmeal kk : kks) {
            VOMOBsGet vv = new VOMOBsGet();
            BeanUtils.copyProperties(kk, vv);
            vvs.add(vv);
        }

        for (VOMOBsGet vv : vvs) {
            List<CheckGroup> gg = setmealMapper.getGroups(vv.getId());
            vv.setCheckGroups(gg);
            for (CheckGroup cg : gg) {
                List<CheckItem> ii = setmealMapper.getCheckItems(cg.getId());
                cg.setCheckItems(ii);
            }
        }
        return vvs;
    }

    @Override
    public VOMOBsGet findById(Integer id) {
        Setmeal kk = setmealMapper.getSetmealById(id);
        VOMOBsGet vv = new VOMOBsGet();
        BeanUtils.copyProperties(kk, vv);
        List<CheckGroup> gg = setmealMapper.getGroups(id);
        vv.setCheckGroups(gg);
        for (CheckGroup cg : gg) {
            List<CheckItem> ii = setmealMapper.getCheckItems(cg.getId());
            cg.setCheckItems(ii);
        }

        return vv;

    }
}
